//*************************************************************************************
//* 作    者： 
//* 创建时间： 2021-10-08 10:05:02
//*  描    述：

//* ************************************************************************************
using System;
using UnityEngine;

public class ScaleChildBehaviour : MonoBehaviour 
{
    [SerializeField]
    protected float m_scaleDistanceFactor = 1.1f;
    protected Vector3 m_startScale;
    protected int m_timer;

    void Awake()
    {
        m_startScale = transform.localScale;
    }

    void OnEnable()
    {
        m_timer = TimerAgent.Instance.RegistLoop(UpdateScale, 0.2f);
    }

    private bool UpdateScale()
    {
        var distance = transform.localPosition.magnitude;
        transform.localScale = m_startScale * distance * m_scaleDistanceFactor;
        return !isActiveAndEnabled;
    }

    void OnDisable()
    {
        TimerAgent.Instance.StopTimer(m_timer);
    }
}
